<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发布房源</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/public.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/header.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/bottom.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/entry.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all"/>
</head>
<body>
<div class="main">
    <div class="header">
        <div class="nav">
            <a href="${pageContext.request.contextPath}/renting/index.jsp" class="nav_title">好客租房</a>
            <select class="select">
                <option value="重庆">重庆</option>
                <option value="贵阳">贵阳</option>
                <option value="重庆">重庆</option>
                <option value="贵阳">贵阳</option>
            </select>
            <ul class="nav_ul">
                <li><a href="${pageContext.request.contextPath}/renting/index.jsp">首页</a></li>
                <li><a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">轻松找房</a></li>
                <li><a href="${pageContext.request.contextPath}/renting/pages/onther/entry.jsp" style="color: #2981c8;">房东入驻</a></li>
                <li><a href="${pageContext.request.contextPath}/renting/pages/onther/chat_news.jsp">消息</a></li>
                <c:if test="${sessionScope.drom.isHouse==1}">
                    <li><a href="${pageContext.request.contextPath}/userInfo/">主页</a></li>
                </c:if>
                <c:if test="${sessionScope.drom.isHouse==0}">
                    <li><a href="${pageContext.request.contextPath}/userInfo/">房东</a></li>
                </c:if>
                <li><a href="${pageContext.request.contextPath}/renting/pages/onther/login.jsp">登录</a></li>
            </ul>
            <img src="${pageContext.request.contextPath}/renting/img/icon/lianxi-1.png" class="nav_img">
            <p class="nav_phone">
                <span>13301131116</span>
                <span>13301131116</span>
            </p>
        </div>
    </div>
    <div class="section">
        <h2>发布房源:</h2>
        <form>
            <table border="0" cellspacing="0" cellpadding="0" class="mytable">
                <tr>
                    <td colspan="4">房源信息</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="hidden" name="communityId" id="communityId">
                        小区名称:<input id="sousuo_text" type="text" class="" placeholder="搜  索  小  区" style="height: 100%;width: 600px;border: 0px;">
                        <span id="cityName"></span>
                        <ul id="sousuo" class="layui-nav-tree" style="width: 600px;float: left;margin-left:65px;border-bottom-right-radius: 15px;border-bottom-left-radius: 15px;border: 1px solid whitesmoke;background-color: white;position: absolute;z-index: 99">

                        </ul>
                    </td>
                    <td colspan="2">
                        建筑类型:<select name="buildingType" id="buildingType" lay-search="" style="border: 0px;width: 200px;height: 50px;text-align: center;">
                        <option value="公寓">公寓</option>
                        <option value="商品房">商品房</option>
                        <option value="学区房">学区房</option>
                        <option value="微利房">微利房</option>
                        <option value="普通住宅">普通住宅</option>
                    </select>
                    </td>
                </tr>
                <tr>
                    <td>装修情况:<select name="renovationCondition" id="renovationCondition" lay-search="" style="border: 0px;width: 200px;text-align: center;">
                        <option value="精装">精装</option>
                        <option value="简装">简装</option>
                        <option value="毛胚">毛胚</option>
                    </select></td>
                    <td>租金:&emsp;<input type="number" name="price" id="price" value="" style="border: 0px;"/></td>
                    <td>
                        面积:&emsp;<input type="number" name="constructionArea" id="constructionArea" value="" style="border: 0px;width: 50px"/><svg t="1639046996437" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2307" width="20" height="20"><path d="M624.9216 343.8336c-33.9712 0-63.36 9.984-88.2432 29.9776-12.1344 9.7024-25.7536 25.472-40.9344 47.3088-17.5872-27.2384-36.096-47.0016-55.5008-59.0592-19.4048-12.1344-45.7728-18.2016-79.1296-18.2016-38.1952 0-70.0416 9.984-95.488 29.9776-15.8208 12.1344-22.9632 18.2528-43.6736 41.8304l0-38.5792c0-11.3152-9.1648-20.48-20.48-20.48L120.5248 356.608c-11.3152 0-20.48 9.1648-20.48 20.48l0 443.008c0 11.2896 9.1392 20.4288 20.4288 20.4288l86.5024 0c11.2896 0 20.4288-9.1392 20.4288-20.4288L227.4048 545.7664c0-29.1584 6.1696-52.1984 18.6112-69.1456 12.4416-16.9472 32.6144-25.472 60.5184-25.472 33.9456 0 56.3712 11.1872 67.2768 33.6128 6.0672 12.1344 9.1136 33.6896 9.1136 64.64l0 270.6432c0 11.2896 9.1392 20.4288 20.4288 20.4288l86.5024 0c11.2896 0 20.4288-9.1392 20.4288-20.4288L510.2848 550.272c0-30.9504 6.8096-55.168 20.48-72.7808 13.6192-17.536 35.6096-26.368 65.92-26.368 21.248 0 38.0416 7.3984 50.4832 22.272 12.4416 14.8736 18.6624 39.2448 18.6624 73.216l0 273.3824c0 11.2896 9.1392 20.4288 20.4288 20.4288l86.5024 0c11.2896 0 20.4288-9.1392 20.4288-20.4288L793.1904 505.7024c0-51.5328-15.7696-91.4176-47.3088-119.6288C714.3936 357.888 674.048 343.8336 624.9216 343.8336z" p-id="2308"></path><path d="M884.2752 306.8416c6.912-4.8384 13.9264-9.728 20.992-14.72 10.9312-7.3984 18.9696-14.4896 24.1152-21.248 7.7312-9.984 11.5968-21.4784 11.5968-34.5088 0-16.896-5.5552-30.1312-16.6656-39.68-11.1104-9.6-25.1648-14.3616-42.24-14.3616-13.184 0-24.448 3.1232-33.7664 9.3952-14.8224 9.984-22.1952 27.0336-22.1952 51.1488l32.8192 0c0-9.3184 1.1264-16.256 3.3792-20.7616 3.8656-7.552 10.9312-11.3408 21.248-11.3408 7.7056 0 13.7472 2.6624 18.0992 7.9616 3.712 4.5056 5.5552 9.984 5.5552 16.4096 0 10.4448-5.4016 20.4288-16.1536 29.9008-4.0192 3.5584-13.0304 10.3936-27.0336 20.5312-16.896 12.2112-28.2368 24.448-34.0224 36.6848-3.8656 8.0384-5.7856 18.4832-5.7856 31.36l116.7872 0 0-29.9264-74.0864 0C868.992 319.5648 874.7776 313.9328 884.2752 306.8416z" p-id="2309"></path></svg>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        支付方式：&emsp;
                        <input  type="radio" name="paymentMethod" class="paymentMethod" value="0" >&nbsp;免押金&emsp;
                        <input  type="radio" name="paymentMethod" class="paymentMethod" value="1" checked>&nbsp;押一付一&emsp;
                        <input  type="radio" name="paymentMethod" class="paymentMethod" value="2" >&nbsp;押一付二&emsp;
                        <input  type="radio" name="paymentMethod" class="paymentMethod" value="3" >&nbsp;押一付三
                    </td>
                    <td colspan="2">
                        租赁方式：&emsp;
                        <input  type="radio" name="rentalType" class="rentalType" value="整租" checked>&nbsp;整租&emsp;
                        <input  type="radio" name="rentalType" class="rentalType" value="合租" >&nbsp;合租
                    </td>
                </tr>
                <tr>
                    <td>租房类型:<select name="buildingType" id="houseType1" lay-search="" style="border: 0px;width: 50px;text-align: center;">
                        <option value="一">一</option>
                        <option value="二">二</option>
                        <option value="三">三</option>
                        <option value="四">四</option>
                    </select><span style="background-color: whitesmoke;">室</span>
                        <select name="buildingType" lay-search="" id="houseType2" style="border: 0px;width: 50px;text-align: center;">
                            <option value="一">一</option>
                            <option value="二">二</option>
                        </select><span style="background-color: whitesmoke;">厅</span>
                        <select name="buildingType" lay-search="" id="houseType3" style="border: 0px;width: 50px;text-align: center;">
                            <option value="一">一</option>
                            <option value="二">二</option>
                        </select><span style="background-color: whitesmoke;">卫</span>
                    </td>
                    <td>朝向:<select name="towards" id="towards" lay-search="" style="border: 0px;width: 150px;text-align: center;">
                        <option value="朝南">朝南</option>
                        <option value="朝北">朝北</option>
                        <option value="朝西">朝西</option>
                        <option value="朝东">朝东</option>
                        <option value="东南">东南</option>
                        <option value="东北">东北</option>
                        <option value="西南">西南</option>
                        <option value="西北">西北</option>
                    </select>

                    </td>
                    <td>楼层情况:<select name="floorSituation" lay-search="" id="floorSituation" style="border: 0px;width: 150px;text-align: center;">
                        <option value="低层">低层（1-10）</option>
                        <option value="中层">中层（10-20）</option>
                        <option value="高层">高层（20以上）</option>
                    </select></td>
                </tr>
                <tr>
                    <td colspan="4">房屋配置:<input type="text" name="housingConfiguration" id="housingConfiguration" value="" /></td>
                </tr>
                <tr>
                    <td colspan="4"></td>
                </tr>
                <tr>
                    <td colspan="4" valign="top">
                        <p style="float: left;">房屋描述:</p>
                        <textarea rows="5" cols="100" id="houseDescribe" style="resize: none;float: left;margin-left: 8px;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" valign="top">
                        房产证/租赁合同图像:
                        <div class="upload">
                            <label style="display: inline-block;">
                                <img src="${pageContext.request.contextPath}/renting/img/addIMG.png" class="imgupl close1">
                                <input type="file" name="upLoad" id="houseImg" class="imgup1" value="" hidden="hidden"/>
                                <p>添加图片</p>
                            </label>
                        </div>
                    </td>
                    <td colspan="2" valign="top">
                        房屋图像:
                        <div class="upload">
                            <label style="display: inline-block;">
                                <img src="${pageContext.request.contextPath}/renting/img/addIMG.png" class="imgupl close2">
                                <input type="file" name="upLoads" id="houseImgs" class="imgup2" value="" hidden="hidden" multiple="multiple"/>
                                <p>添加图片</p>
                            </label>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="btn_box">
                <input type="reset" id="onNo" value="取消" />
                <input type="submit" id="Save" value="提交" />
            </div>
            <div style="clear: both;"></div>
        </form>
    </div>
    <div class="bottom">
        <p>沪公网安备 31011402005354号</p>
    </div>
</div>
</body>
</html>
<script src="${pageContext.request.contextPath}/renting/js/jQuery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/renting/js/entry.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/header.js"></script>
<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script type="text/javascript">
    var login=sessionStorage.getItem("login");
    var url="";
    if(login==1){
        url="${pageContext.request.contextPath}/renting/pages/tenant/inspection.jsp";
    }
    if(login==2){
        url="${pageContext.request.contextPath}/renting/pages/landlord/release.jsp";
    }
    judge_login(url,"${pageContext.request.contextPath}/renting/pages/onther/login.jsp");



    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //取消事件
        $("#onNo").click(function () {
            window.location.href="${pageContext.request.contextPath}/renting/index.jsp"
        })

        //小区搜索事件
        $("#sousuo_text").on("input",function(e){
            //获取input输入的值
            // console.log(e.delegateTarget.value);
            var txt=e.delegateTarget.value;
            $("#sousuo").html(null);
            if(txt!=null && txt!=""){
                var obj={"cityId":${city.rid},"name":txt}
                $.ajax({
                    url:"${pageContext.request.contextPath}/city/queryComByLikeName",
                    type:"post",
                    data:"condition="+JSON.stringify(obj),
                    dataType:"json",
                    success:(rs)=>{

                        $.each(rs,function (i,j){
                            $("#sousuo").append("<li value='"+j.rid+"' class='layui-nav-item' ><span>"+j.comName+"</span>&emsp;&emsp;<span style='float: right;'><"+j.cityName+"></span></li>");
                        })
                        $("#sousuo>li").hover(function(){
                            $(this).addClass("layui-this")
                        },function(){
                            $(this).removeClass("layui-this")
                        })
                        $("#sousuo>li").click(function (data){

                            $("#sousuo_text").val($(this).find("span").eq(0).text());
                            $("#sousuo").html(null);
                            $("#communityId").val(this.value);
                            $("#cityName").text($(this).find("span").eq(1).text());
                        })

                    }
                })
                form.render('select');
            }
        });

        //添加事件
        $("#Save").click(function () {
            if(${drom.isAttest==0}){
                layer.msg("您当前未实名认证",{icon:0,time:500},function () {
                    if(${loginMethod==1}){
                        window.location.href="${pageContext.request.contextPath}/renting/pages/landlord/ID_verification.jsp";
                    }else{
                        window.location.href="${pageContext.request.contextPath}/renting/pages/tenant/ID_verification.jsp";
                    }
                })
                return false;
            }

            let communityId=$("#communityId").val();
            let sousuo_text=$("#sousuo_text").val();

            let buildingType=$("#buildingType").val();
            let renovationCondition=$("#renovationCondition").val();
            let price=$("#price").val();
            let constructionArea=$("#constructionArea").val();
            let paymentMethod=$(".paymentMethod:checked").val();
            let rentalType=$(".rentalType:checked").val();
            let houseType1=$("#houseType1").val();
            let houseType2=$("#houseType2").val();
            let houseType3=$("#houseType3").val();
            let towards=$("#towards").val();
            let floorSituation=$("#floorSituation").val();
            let housingConfiguration=$("#housingConfiguration").val();
            let houseDescribe=$("#houseDescribe").val();

            if(communityId==null || communityId=="" || sousuo_text==null || sousuo_text=="" || price==null || price=="" || housingConfiguration==null || housingConfiguration=="" || houseDescribe==null || houseDescribe==""){
                layer.msg("请填写完整信息")
                return false;
            }
            let houseType=houseType1+"室"+houseType2+"厅"+houseType3+"卫";
            let house={"userId":${drom.rid},"communityId":communityId,"buildingType":buildingType,"renovationCondition":renovationCondition,"price":price,"constructionArea":constructionArea,"paymentMethod":paymentMethod,"rentalType":rentalType,"towards":towards,"floorSituation":floorSituation,"housingConfiguration":housingConfiguration,"houseDescribe":houseDescribe,"houseType":houseType};


            let formData = new FormData();
            let obj=$("#houseImg")[0].files;
            formData.append("upLoad",obj[0]);
            let objs=$("#houseImgs")[0].files;
            for(let i=0;i<objs.length;i++){
                formData.append("upLoads",objs[i]);
            }

            formData.append("data",JSON.stringify(house));
            console.log(JSON.stringify(formData))
            // let imgs= $("#houseImg")[0].files;

            // console.log(JSON.stringify(house));
            // alert(house)
            $.ajax({
                url:"${pageContext.request.contextPath}/house/addHouse",
                type:"post",
                data:formData,
                dataType:"text",
                processData: false,
                contentType: false,
                success:(rs)=>{
                    if(rs=="OK"){
                        layer.msg("提交成功",{icon:1,time:500},()=>window.location.href="${pageContext.request.contextPath}/renting/pages/landlord/release.jsp");
                    }else{
                        layer.msg("提交失败",{icon:2,time:500});
                    }
                }
            })
            return false;

        })

    });

</script>
